package com.company.dao;

import com.company.config.DbConfig;
import com.company.model.Admin;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class DaoTest {

    public static List<Admin> getAdmin(){
        Connection conn=null;
        Statement stat=null;
        ResultSet rs = null;
        List<Admin> admin =new ArrayList<>();
        try {
            conn = DbConfig.getConn();
            stat = conn.createStatement();
            rs=stat.executeQuery("select * from admin");
            while(rs.next()){
                int id=rs.getInt("id");
                String username = rs.getString("username");
                String password =rs.getString("password");
                String time = String.valueOf(rs.getTimestamp("signout_time"));
                Admin admin1=new Admin();
                admin1.setId(id);
                admin1.setUsername(username);
                admin1.setPassword(password);
                admin1.setSignout_time(time);
                admin.add(admin1);
            }
        }catch (SQLException e){
            e.printStackTrace();
        }finally {
            DbConfig.close(conn,stat,rs);
        }

        return admin;

    }

    public static void main(String[] args) {
        List<Admin> admins=DaoTest.getAdmin();
        for(Admin a : admins){
            System.out.println(a);
        }
    }



}
